package com.example.service.impl;

import com.example.service.KafkaMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

/**
 * Kafka消息服务实现类
 */
@Slf4j
@Service
public class KafkaMessageServiceImpl extends KafkaMessageService {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    // 缓存失败主题
    private static final String CACHE_FAILURE_TOPIC = "cache-failure-topic";

    /**
     * 发送缓存失败消息到Kafka
     * @param message 消息内容
     */
    @Override
    public void sendCacheFailureMessage(String message) {
        try {
            kafkaTemplate.send(CACHE_FAILURE_TOPIC, message);
            log.info("成功发送缓存失败消息到Kafka: {}", message);
        } catch (Exception e) {
            log.error("发送缓存失败消息到Kafka失败: {}", e.getMessage(), e);
        }
    }
}